package com.aaa.controller;

import com.aaa.entity.Back_User;
import com.aaa.entity.Menu;
import com.aaa.service.impl.BackUserImpl;
import com.aaa.service.impl.MenuServiceImpl;
import com.aaa.utils.password;
import com.aaa.utils.upload;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: AdminController
 * @Description: TODO
 * @Author: 86139
 * @Date: 2021/9/6 9:09
 * @Version:1.0
 **/
@RestController
@RequestMapping("admin")
public class AdminController {
    @Resource
    MenuServiceImpl menuService;
    @Resource
    BackUserImpl backUser;
    //    设置左侧导航栏
//    admin 全局方法  都要使用
    @RequestMapping("finByRid")
    @ResponseBody
    public List<Menu> finByRid(Integer rid){
        return menuService.finByRid(rid);
    }
    @RequestMapping("geren")
    @ResponseBody
    public boolean geren(Back_User back_user){
        return backUser.updateById(back_user);
    }
    @PostMapping("/upload")
    public boolean upload(@RequestParam("head") MultipartFile head,Integer uid){
        System.out.println(uid);
        String upload = new upload().upload(head);
        Back_User back_user = new Back_User();
        back_user.setUid(uid);
        back_user.setPhoto(upload);
        return backUser.updateById(back_user);
    }
    @RequestMapping("updatePass")
    @ResponseBody
    public boolean updatePass(Integer uid,String pwd){
        String s = new password().passEncoding(pwd);
        Back_User back_user = new Back_User();
        back_user.setPassword(s);
        back_user.setUid(uid);
        return backUser.updateById(back_user);
    }
}
